/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.gonggao.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizGonggao;
import com.nmf.dao.gen.bean.BizGonggaoExample;
import com.nmf.dao.gen.BizGonggaoMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * 公告Service
 * @author bm
 * @version 2019-02-15
 */
@Service
@Transactional(readOnly = true)
public class BizGonggaoService{

	@Autowired
	BizGonggaoMapper bizGonggaoMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizGonggao get(String no) {
		return bizGonggaoMapper.selectByPrimaryKey(no);
	}
	
	public List<BizGonggao> findList(BizGonggao bizGonggao) {
		BizGonggaoExample bizGonggaoExample = new BizGonggaoExample();
		BizGonggaoExample.Criteria criteria = bizGonggaoExample.createCriteria();
		
		return bizGonggaoMapper.selectByExample(bizGonggaoExample);
	}
	
	public Page<BizGonggao> findPage(Page<BizGonggao> page, BizGonggao bizGonggao) {
		BizGonggaoExample bizGonggaoExample = new BizGonggaoExample();
		BizGonggaoExample.Criteria criteria = bizGonggaoExample.createCriteria();
		
		bizGonggaoExample.setPage(page);
		
		List<BizGonggao> dlist = bizGonggaoMapper.selectByExample(bizGonggaoExample);
		page.setList(dlist);
		page.setCount(bizGonggaoMapper.countByExample(bizGonggaoExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizGonggao bizGonggao) {
		if(StringUtils.isNotEmpty(bizGonggao.getId())&&get(bizGonggao.getId())!=null) {
			bizGonggaoMapper.updateByPrimaryKeySelective(bizGonggao);
		}else {
			Date date = new Date();
			bizGonggao.setCreateDate(date);
			bizGonggao.setId(idGenerater.genClsNo("bizGonggao"));
			bizGonggao.setUpdateDate(date);
			bizGonggaoMapper.insertSelective(bizGonggao);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizGonggao bizGonggao) {
		bizGonggaoMapper.deleteByPrimaryKey(bizGonggao.getId());
	}
	
}